<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/5/31
 * Time: 16:32
 */

namespace Weixin\Model\Weixin;


use Think\Model;

class WeixinModel extends Model
{
    public function addWeixin($openid, $nickname, $headimgurl, $subscribe)
    {
        return $this->add(array('openid' => $openid, 'nickname' => $nickname, 'headimgurl' => $headimgurl, 'subscribe' => $subscribe));
    }

    public function seekWeixin($id)
    {
        return $this->where(array('id' => $id))->find();
    }

    public function findWeixin($openid)
    {
        return $this->where(array('openid' => $openid))->find();
    }

    public function changeSubscribe($openid, $subscribe)
    {
        return $this->where(array('openid' => $openid))->save(array('subscribe' => $subscribe));
    }

    public function cha()
    {
        //return $this->table(array('user_weixin' => 'uw', 'weixin' => 'w'))->select();
         return $this->table(array('user_weixin' => 'uw', 'weixin' => 'w'))->where('w.id=uw.weixin_id')->select();
        //或

        // return $this->field('u.update_time,w.headimgurl')->table('user u,weixin w')->select();
    }
}